package pl.edu.mimuw.irs.core.model.design.net;

import pl.edu.mimuw.irs.core.global.IDManager;
import pl.edu.mimuw.irs.core.model.design.exception.InternalDesignException;
import pl.edu.mimuw.irs.core.model.design.exception.InternalDesignException.DesignCause;
import pl.edu.mimuw.irs.core.model.petrinet.Arc;

/**
 * @author Jakub Rauch
 * Created on: 2009-05-07
 */
public class IRSArc extends Arc {

	private static final long serialVersionUID = -7803347977458403082L;
	
	// *** Attributes
	
	// *** Constructors

	/** General constructor. */
	public IRSArc(IDManager idManager, IRSNode source, IRSNode target, int weight) {
		super(idManager, source, target, weight);
	}
	
	public IRSArc(IDManager idManager, IRSNode source, IRSNode target) {
		super(idManager, source, target);
	}
	
	// *** Methods

	public IRSArc copy(IRSNode source,
			IRSNode target) {
		if (source instanceof IRSPlace && target instanceof IRSTransition) {
			IRSPlace place = (IRSPlace) source;
			IRSTransition transition = (IRSTransition) target;
			IRSArc arc = new IRSArc(getIdManager(), place, transition, getWeight());
			arc.setVertices(getVertices());
			return arc;
		} else if (source instanceof IRSTransition && target instanceof IRSPlace) {
			IRSTransition transition = (IRSTransition) source;
			IRSPlace place = (IRSPlace) target;
			IRSArc arc = new IRSArc(getIdManager(), transition, place, getWeight());
			arc.setVertices(getVertices());
			return arc;
		} else {
			throw new InternalDesignException(DesignCause.NOT_ALLOWED_ARC_NODES, 
					source, 
					target);
		}
	}
}
